
from datetime import datetime
from pydantic import BaseModel, EmailStr, Field
from sqlalchemy import BigInteger, Boolean, Column, DateTime, ForeignKey, Integer, \
    String, Text, UniqueConstraint
from sqlalchemy.orm import relationship
from sqlalchemy.sql import func
from app.common.database import Base
from app.models.base import TableBase, TableBase2


class PayChannel(TableBase):
    """支付通道表"""
    __tablename__ = "t_pay_channel"
    id = Column(Integer, primary_key=True, index=True)
    pay_channel_code = Column(String(24), unique=True, index=True, nullable=False, comment='通道编码')
    pay_channel_name = Column(String(32), nullable=False, comment='通道名称')
    status = Column(Integer, nullable=False, comment='通道状态 1.正常;2.停用')


class ChannelFee(TableBase):
    """通道成本费率表"""
    __tablename__ = "t_channel_fee_rate"
    id = Column(Integer, primary_key=True, index=True)
    pay_channel_code = Column(String(24), nullable=False,  comment='通道编码')
    pay_channel_name = Column(String(32), nullable=False, comment='通道名称')
    fee_mode = Column(Integer, nullable=False, comment='计费模式 1.单笔固定 2.百分比')
    fee_value = Column(Integer, nullable=False, comment='费率值')
    status = Column(Integer, nullable=False, comment='状态')

    __table_args__ = (
        UniqueConstraint('pay_channel_code', 'fee_mode'),
    )


class ChannelMerchant(TableBase):
    """通道商户表"""
    __tablename__ = "t_channel_merchant"

    id = Column(Integer, primary_key=True, index=True)
    pay_channel_code = Column(String(32), nullable=False, comment='支付通道编号')
    channel_merc_no = Column(String(24), nullable=False, comment='通道商户编号')
    channel_merc_name = Column(String(32), comment='通道商户名')
    status = Column(Integer, nullable=False, comment='状态 1.启用;2.停用')
    channel_merc_config = Column(Text, default='{}', comment='通道商户配置')

    __table_args__ = (
        UniqueConstraint('pay_channel_code', 'channel_merc_no'),
    )
